package Volume1.ch6;

import javax.swing.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;

/**
 * 在一个比较器和一个监听器中使用lambda表达式
 * @Auther jacob
 * @Date 2020/8/8 11:02
 */
public class LambdaTest {

    private static final int DELAY_TIME= 1*1000; // 暂停时间

    public static void main1(String[] args) {
        String[] strings = new String[]{"aaaaa", "bbbb", "ccc", "dd", "e"};

        // 按照字符串长度从大到小排序
        Arrays.sort(strings, (first, second) -> second.length() - first.length());
        System.out.println(Arrays.toString(strings));

        // 按照字符串长度从小到大排序
        Arrays.sort(strings, Comparator.comparingInt(String::length));
        System.out.println(Arrays.toString(strings));

        Timer timer = new Timer(DELAY_TIME, e -> System.out.println("the time is " + new Date()));
        timer.start();
        JOptionPane.showMessageDialog(null, "退出程序");
        System.exit(0);

    }

    public static void main(String[] args) {
        String[] strings = new String[]{"e", "b", "d", "c", "a"};

        Arrays.sort(strings, String::compareToIgnoreCase);
//        Arrays.sort(strings, (a, b)->(String.CASE_INSENSITIVE_ORDER.compare(a,b)));
        System.out.println(Arrays.toString(strings));

    }
}
